package com.momoauth.common.security.dao;

import com.momoauth.common.security.entity.Role;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Repository;

import javax.annotation.Resource;
import java.util.List;

@Repository
public class RoleDao {

    @Resource
    JdbcTemplate jdbcTemplate;

    /**
     * 根据用户ID取出用户拥有的角色名称列表
     * @param user_id
     * @return
     */
    public List<Role> getRoleNameList(Long user_id) {
        String sql = "SELECT roleName FROM role INNER JOIN user_role ON roleId = role_id WHERE user_id = ?";
        return jdbcTemplate.query(sql, new BeanPropertyRowMapper<>(Role.class), user_id);
    }
}
